package cn.fraudmetrix.octopus.modules.jacoco.service;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;

/**
 * @author libao.zheng
 * @email libao.zheng@tongdun.cn
 * @date 2018/11/28 17:28
 */
public class Shell {
    private static final Logger LOGGER = LoggerFactory.getLogger(Shell.class);

    public static String execCmd(String cmd, File dir) throws IOException {
        StringBuilder builder = new StringBuilder();
        Process process = Runtime.getRuntime().exec(cmd, null, dir);
        LineNumberReader br = new LineNumberReader(new InputStreamReader(process.getInputStream()));
        String line;
        while ((line = br.readLine()) != null) {
            builder.append(line);
            builder.append("\n");
        }
        process.destroy();
        return builder.toString();
    }

}
